package acom.test.swing.bb;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.UIManager;


public class SetFrame {
	
	private JFrame frame;
	private JPanel mainPanel;
	private JPanel cardPanel;
	private CardLayout cardlayout;
	
	private JButton in_but;
	private JButton set_but;
	
	private JPanel peoplePanel;
	private JPanel prizePanel;
	
	static final int WIDTH = 500;
	static final int HEIGHT = 450;
	
	private int position_x=30;
	private int position_y=30;
	
	private int but_w=120;
	private int but_h=30;
	private int cardpane_w=400;
	private int cardpane_h=300;
	
	public SetFrame(){
		
		frame = new JFrame();
		frame.setTitle("CardLayoutTest");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		try {
			// 将LookAndFeel设置成Windows样式
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		mainPanel = new JPanel();		
		mainPanel.setLayout(null);
				
		in_but = new JButton("导入文件");
		set_but = new JButton("设置奖项");
		
		cardPanel =  new JPanel();
		cardlayout = new CardLayout();
		cardPanel.setLayout(cardlayout);
		
		
		peoplePanel = new PeoplePanel();
		prizePanel = new PrizePanel();
		
		cardPanel.add(peoplePanel, "p1");
		cardPanel.add(prizePanel, "p2");
		
		init();
						
		
		mainPanel.add(in_but);
		mainPanel.add(set_but);								
		mainPanel.add(cardPanel);	
		frame.setSize(WIDTH, HEIGHT);
		frame.add(mainPanel);
		frame.setVisible(true);
	}
	
	public void init(){
		in_but.setBounds(position_x, position_y, but_w, but_h);
		set_but.setBounds(position_x+180, position_y, but_w, but_h);
		cardPanel.setBounds(position_x, position_y+50,cardpane_w , cardpane_h);
		
		peoplePanel.setBackground(Color.WHITE);
		prizePanel.setBackground(Color.WHITE);
		
		in_but.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				cardlayout.show(cardPanel, "p1");
			}
		});
		set_but.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				cardlayout.show(cardPanel, "p2");
			}
		});
		
	}
	
	
	public static void main(String[] args) {
		new SetFrame();
	}
						
}

